<%@page import="com.pb.poem.entity.Common"%>
<%@page import="com.pb.poem.util.Page"%>
<%@page import="com.pb.poem.entity.Poem"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@include file="../common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="../js/jquery-1.5.1.mini.js"></script>

<script type="text/javascript">
	function back() {
		window.location="show.jsp";
	}
	function page_nav(num) {
		var frm=document.getElementById("formpage");
		frm.inputPage1.value=num;
		frm.submit();
	}
	function jump_to(pageno) {
		var regexp = /^\d+$/;
		if (!regexp.test(pageno)) {
			alert("请输入正确的数字");
			return false;
		} else {
			page_nav(pageno);
		}
	}
	function showImage(pid) {
		document.getElementById(pid).style.display = "block";
	}
	function hideImage(pid) {
		document.getElementById(pid).style.display = "none";
	}
	function addAnsweer() {
		window.location="showoneself.jsp";
	}
	function toadd() {
		window.location="../comment/addcommon.jsp";
	}
	 function add_comment(id) {
	var ajaxForm = $("#ajaxForm"+id);
		$.post("../comment/addcommon.jsp",ajaxForm.serialize(),function(data){
        $("#comment"+id).append(data);
        
        var textareaid=document.getElementById("textid"+id);
        textareaid.value="";
     		});
	}
	 function del_comment(id,pid) {
		 if(confirm("确定是否你删除?")){
			var ajaxForm = $("#ajaxForm"+id);
			$.post("../comment/delcommon.jsp?pid="+pid,ajaxForm.serialize(),function(data){
            $("span").remove(".aa"+pid);
			});
		 }
		 }
	</script>
</head>

<body>
	<table class="list">
		<c:forEach var="poem" items="${List}" varStatus="status">
			<table width="600" border="0">
				<tr>
					<td width="500" align="center">${poem.poemname}</td>
				</tr>
				<tr>
					<td align="center">${poem.dynasty}&nbsp;&nbsp;&nbsp;${poem.author}</td>
				</tr>
				<tr>
					<td align="center">${poem.content}</td>
				</tr>
				<tr>
<td><a href="editpoem.jsp?id=${poem.id}">修改</a> | 
<a	href="javascript:if(confirm('确认是否删除？'))  window.location='deletepoem.jsp?id=${poem.id}'">删除</a><br />
	<c:set var="poemId" value="${poem.id}" scope="request"></c:set> <%
 	int id = (Integer) request.getAttribute("poemId");
 		List<Common> list = poemService.getCommonByid(id);
 		request.setAttribute("List", list);
 %>
       	<div id="comment${poem.id}">
	<c:forEach var="common" items="${List}" varStatus="status">
		<span class="aa${common.pid}">${common.content}
			&nbsp;&nbsp;&nbsp;&nbsp; <fmt:formatDate value="${common.date}"
				pattern="yyyy-MM-dd HH:mm:ss" />&nbsp;&nbsp; <input
			type="button" onclick="del_comment(${poem.id},${common.pid})"
			value="删除评论"> <br />
		</span>
	</c:forEach>
</div>

<form id="ajaxForm${poem.id}" action="../comment/addcommon.jsp" method="post">
	<div id="${poem.id}" style="display: none">
		<textarea name="content${poem.id}" id="textid${poem.id}"></textarea>
		<input type="hidden" name="poemid" value="${poem.id}" /> <br />
		<input id="b1" value="评论" type="button"
			onclick="add_comment(${poem.id})" /> <input type="button"
			value="隐藏评论" onclick="hideImage(${poem.id})" />
						
		</div>
		<input type="button" id="id" value="发表评论"
			onclick="showImage(${poem.id})" />
	</form></td>
		</tr>
	</table>
</c:forEach>
</table>
	<form action="showoneself.jsp" id="formpage" method="post">
	<input type="hidden" name="pageIndex" value="1" />
	            <div>
					<li>共${totalCount}条记录&nbsp;&nbsp; ${pageIndex}/${totalPage}页</li>
					<c:if test="${pageIndex>1}">
						<a href="javascript:page_nav(1)">首页</a>
						<a href="javascript:page_nav(${pageIndex-1})">上一页</a>
					</c:if>
					<c:if test="${pageIndex<totalPage }">
						<a href="javascript:page_nav(${pageIndex+1})">下一页</a>
						<a href="javascript:page_nav(${totalPage})">最后一页</a>
					</c:if>
					</ul>
					<span class="page-go-form"><label>跳转至</label> 
					<input type="text" name="inputPage1" id="inputPage" class="page-key" />页
						<button type="button" class="page-btn"
							onClick='jump_to(document.getElementById("inputPage").value)'>GO</button>
					</span>
				</div>	
			</form>
			<div>
		<input type="button" value="返回" onclick="back();"/>
	</div>
</body>
</html>